unit cargaCheque;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Provider, SqlExpr, DB, DBClient, DBLocal, DBLocalS, Grids,
  DBGrids, RXDBCtrl, StdCtrls, Buttons, ExtCtrls, DBCtrls;

type
  TfrmCargaCheque = class(TForm)
    RxDBGrid1: TRxDBGrid;
    cdsCargaCheque: TSQLClientDataSet;
    cdsCargaChequeID_CHEQUE: TIntegerField;
    cdsCargaChequeID_CUENTA: TSmallintField;
    cdsCargaChequeFECHA_EMISION: TSQLTimeStampField;
    cdsCargaChequeFECHA_COBRO: TSQLTimeStampField;
    cdsCargaChequeIMPORTE: TFloatField;
    cdsCargaChequeCHEQUE: TStringField;
    cdsCargaChequeDESTINO: TStringField;
    cdsCargaChequeCOBRADO: TStringField;
    cdsCargaChequeOBSERVACIONES: TStringField;
    sCargaCheque: TDataSource;
    btnGrabar: TBitBtn;
    DBNavigator1: TDBNavigator;
    procedure btnGrabarClick(Sender: TObject);
    procedure sCargaChequeStateChange(Sender: TObject);
    procedure cdsCargaChequeNewRecord(DataSet: TDataSet);
  private
    { Private declarations }
  public
    constructor Crear(AOwner: TComponent);
  end;

var
  frmCargaCheque: TfrmCargaCheque;

implementation

uses Unit1;

{$R *.dfm}



{ TForm2 }

constructor TfrmCargaCheque.Crear(AOwner: TComponent);
begin
  inherited Create(Aowner);
  //precarga
  self.cdsCargaCheque.Open;
  self.cdsCargaCheque.Insert;
  self.ShowModal;
end;

procedure TfrmCargaCheque.btnGrabarClick(Sender: TObject);
begin
  if self.cdsCargaCheque.State in [dsInsert, dsEdit] then
    self.cdsCargaCheque.Post;
  if self.cdsCargaCheque.ChangeCount > 0 then
    if (self.cdsCargaCheque.ApplyUpdates(0) <> 0) then
    begin
      Application.MessageBox('Error al grabar en tabla Cheques', 'Error', mb_Ok+mb_IconError);
      Abort;
    end;
  self.Close;
end;

procedure TfrmCargaCheque.sCargaChequeStateChange(Sender: TObject);
begin
  self.btnGrabar.Enabled := (self.cdsCargaCheque.ChangeCount > 0);
end;

procedure TfrmCargaCheque.cdsCargaChequeNewRecord(DataSet: TDataSet);
begin
  self.cdsCargaChequeID_CHEQUE.AsInteger := frmOrdenPago.id;
  self.cdsCargaChequeID_CUENTA.AsInteger := frmOrdenPago.cdsBYCID_CUENTA.AsInteger;
  self.cdsCargaChequeCOBRADO.AsInteger := 0;
  self.cdsCargaChequeFECHA_EMISION.AsDateTime := now;
  self.cdsCargaChequeDESTINO.AsString := frmOrdenPago.cdsProveedorRAZON.AsString;
end;

end.
